﻿@using System.Globalization
@using Abp.Extensions
@using Abp.MultiTenancy
@using ModularTodoApp.MultiTenancy
@model ModularTodoApp.Web.Models.Account.LoginFormViewModel
@section Styles
{
    <environment names="Development">
        <link rel="stylesheet" href="~/view-resources/Views/Account/Login.css" asp-append-version="true" />
    </environment>

    <environment names="Staging,Production">
        <link rel="stylesheet" href="~/view-resources/Views/Account/Login.min.css" asp-append-version="true" />
    </environment>

}
@section Scripts
{
    <environment names="Development">
        <script src="~/view-resources/Views/Account/Login.js" asp-append-version="true"></script>
    </environment>

    <environment names="Staging,Production">
        <script src="~/view-resources/Views/Account/Login.min.js" asp-append-version="true"></script>
    </environment>
}
<div class="container">
    <div id="LoginArea" class="row">
        <div class="col-lg-12">
            <div class="well bs-component">
                <form asp-action="Login" id="LoginForm" class="form-horizontal" method="POST">
                    <input type="hidden" name="returnUrl" value="@ViewBag.ReturnUrl" />
                    <input type="hidden" name="returnUrlHash" />
                    <fieldset>
                        <legend>@L("LogIn")</legend>
                        @if (Model.IsMultiTenancyEnabled)
                        {
                            <div class="form-group">
                                <div class="col-lg-12">
                                    <input type="text" class="form-control" name="tenancyName" placeholder="@L("TenancyName")" required maxlength="@ModularTodoApp.MultiTenancy.Tenant.MaxTenancyNameLength">
                                    <span class="text-muted">@L("CanBeEmptyToLoginAsHost")</span>
                                </div>
                            </div>
                        }
                        else
                        {
                            <input type="hidden" id="TenancyName" value="">
                        }
                        <div class="form-group">
                            <div class="col-lg-12">
                                <input type="text" class="form-control" name="usernameOrEmailAddress" placeholder="@L("UserNameOrEmail")" required maxlength="@ModularTodoApp.Users.User.MaxEmailAddressLength">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-12">
                                <input type="password" class="form-control" name="Password" placeholder="@L("Password")" required maxlength="@ModularTodoApp.Users.User.MaxPlainPasswordLength">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="RememberMe" value="true">
                                        <span class="ripple"></span>
                                        <span class="check"></span> @L("RememberMe")
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-12">
                                <button id="LoginButton" type="submit" class="btn btn-primary"><i class="fa fa-sign-in"></i> @L("LogIn")</button>
                                <a class="btn btn-success" href="@Url.Action("Register")"><i class="fa fa-sign-in"></i> @L("Register")</a>
                            </div>
                        </div>
                    </fieldset>
                </form>
                @{
                    var loginProviders = Context.Authentication
                        .GetAuthenticationSchemes()
                        .Where(s => !s.DisplayName.IsNullOrWhiteSpace())
                        .ToList();

                    Func<string, string> getSocialIconClass = (provider) =>
                    {
                        provider = provider.ToLower(CultureInfo.InvariantCulture);

                        if (provider == "microsoft")
                        {
                            return "windows";
                        }

                        return provider;
                    };
                }

                @if (loginProviders.Count > 0)
                {
                    <div class="login-options">
                        <h4>@L("LoginWith")</h4>
                        <ul class="social-icons">
                            <form asp-action="ExternalLogin" method="post">
                                <input type="hidden" name="returnUrl" value="@ViewBag.ReturnUrl" />
                                <input type="hidden" name="provider" value="" />

                                @foreach (var p in loginProviders)
                                {
                                    <a class="btn btn-default btn-sm fa fa-@(getSocialIconClass(p.DisplayName)) social-login-link" title="@p.DisplayName"
                                       data-provider="@p.DisplayName"
                                       href="javascript:;">
                                    </a>
                                }
                            </form>
                        </ul>
                    </div>
                }
            </div>
        </div>
    </div>
</div>